//
//  SearchResultCaseCell.m
//  BaseProject
//
//  Created by 王洋 on 2020/7/22.
//  Copyright © 2020 王洋. All rights reserved.
//

#import "SearchResultCaseCell.h"

@implementation SearchResultCaseCell


- (void)awakeFromNib {
    [super awakeFromNib];
}

- (void)fillCellWithModel:(CommonOpusModel *)model {

    
    NSString *verticalImg = [TT_OSSManager reSourceUrl:model.verticalImg type:BA_resizeType_max];

    [self.mainImageView sd_setImageWithURL:[NSURL URLWithString:verticalImg] placeholderImage:[UIImage imageNamed:@"placeholder"] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
        
        if (image) {
         
            if (cacheType != SDImageCacheTypeMemory) {
                [UIView transitionWithView:self.mainImageView duration:0.61 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
                    [self.mainImageView setImage:image];
                    self.mainImageView.alpha = 1.0;
                } completion:nil];
            } else {
                self.mainImageView.alpha = 1.0;
                [self.mainImageView setImage:image];
            }
        }
        
    }];
    
    self.mainTitle.text = model.opusName;
    
    self.storeName.text = model.sellerName;
    [self.storeIcon sd_setImageWithURL:[NSURL URLWithString:model.sellerLogo] placeholderImage:[UIImage imageNamed:@"placeholder"]];
    
}

- (void)layoutSubviews {
    [super layoutSubviews];
        
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self pp_clipCorners:UIRectCornerAllCorners radius:6];
        [self.storeIcon pp_clipCorners:UIRectCornerAllCorners radius:self.storeIcon.frame.size.width/2];
    });
    
}

+ (CGFloat)calculateHeightWithWidth:(CGFloat)collectionWeidth {
    
    CGFloat height = ((collectionWeidth-40)/2) + 90;
    return height;
}

+ (CGFloat)calculateHeightWithModel:(CommonOpusModel *)model {
    
    CGFloat imgH = (TTScreenWidth-40)/2;
    CGFloat distance = 10;
    CGFloat titleH = [Utilities getStringHeightWithText:model.opusName font:[UIFont systemFontOfSize:16 weight:UIFontWeightBold] viewWidth:(imgH - 20)];
    CGFloat sellerH = 40;
    return imgH + distance + titleH + sellerH;
}

@end
